package com.lonwin.inspectionmanagement.mvp.ui.adapter;

import android.content.Intent;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lonwin.inspectionmanagement.R;
import com.lonwin.inspectionmanagement.app.AppConstants;
import com.lonwin.inspectionmanagement.app.utils.AppUtil;
import com.lonwin.inspectionmanagement.app.utils.TimeUtils;
import com.lonwin.inspectionmanagement.mvp.model.entity.bean.ConfigBean;
import com.lonwin.inspectionmanagement.mvp.model.entity.bean.UpcommingBean;
import com.lonwin.inspectionmanagement.mvp.ui.activity.EditPatrolRecordActivity;
import com.lonwin.inspectionmanagement.mvp.ui.activity.LookPatrolRecordActivity;

import java.util.List;

public class UpcomingListAdapter extends BaseQuickAdapter<UpcommingBean.DataBean,BaseViewHolder> {
    ConfigBean mconfigBean;
    public UpcomingListAdapter(@Nullable List<UpcommingBean.DataBean> data,ConfigBean configBean) {
        super(R.layout.upcominglist_item,data);
        this.mconfigBean=configBean;
    }

    @Override
    protected void convert(BaseViewHolder helper, UpcommingBean.DataBean item) {
        helper.setText(R.id.upcominglist_item_name,item.getTitle().substring(0,6)+item.getGroupnm()+"巡查记录表")
                .setText(R.id.upcominglist_item_statue,AppUtil.getStrStatus_new(item.getStepstatus()))
                .setText(R.id.upcominglist_item_time,TimeUtils.dateForStr(item.getSystm()));
        /**
         * 0--待提交（刚创建） 1--待审批  2--已审批 9--已存档
         */

        if (item.getStepstatus()==9)
        {
            helper.<TextView>getView(R.id.upcominglist_item_statue).setTextColor(mContext.getResources().getColor(R.color.color_666666));
        }else {
            helper.<TextView>getView(R.id.upcominglist_item_statue).setTextColor(mContext.getResources().getColor(R.color.color_0F9BEF));
        }
        if (mconfigBean.getCurrentRole().getRoleCode().equals(AppConstants.ROLE_HZ))
        {
//            helper.<TextView>getView(R.id.upcominglist_item_tj_txt).setVisibility(View.GONE);
            helper.<TextView>getView(R.id.upcominglist_item_bj_txt).setVisibility(View.GONE);
            helper.<TextView>getView(R.id.upcominglist_item_cd_txt).setVisibility(View.GONE);
            helper.<TextView>getView(R.id.upcominglist_item_ch_txt).setVisibility(View.GONE);
            //河长

            if (item.getStepstatus()==1)
            {
                //只有等于1的时候才可以签批
                helper.<TextView>getView(R.id.upcominglist_item_qp_txt).setVisibility(View.VISIBLE);
            }else {
                helper.<TextView>getView(R.id.upcominglist_item_qp_txt).setVisibility(View.GONE);
            }
            if (item.getStepstatus()==2||item.getStepstatus()==9)
            {

                //只有已签批和已归档可以查看
                helper.<TextView>getView(R.id.upcominglist_item_ch_txt).setVisibility(View.VISIBLE);
                helper.<TextView>getView(R.id.upcominglist_item_ch_txt).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        LookPatrolRecordActivity.startLookPatrolRecordActivity(mContext,item.getXcjlbid(),LookPatrolRecordActivity.Type.LOOK,"查看巡查记录表");
                    }
                });
            }
            helper.<TextView>getView(R.id.upcominglist_item_qp_txt).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    LookPatrolRecordActivity.startLookPatrolRecordActivity(mContext,item.getXcjlbid(),LookPatrolRecordActivity.Type.HZQP,"签批巡查记录表");
                }
            });

        }else {
            //联络员
            helper.<TextView>getView(R.id.upcominglist_item_qp_txt).setVisibility(View.GONE);
//            helper.<TextView>getView(R.id.upcominglist_item_tj_txt).setVisibility(View.GONE);
            helper.<TextView>getView(R.id.upcominglist_item_bj_txt).setVisibility(View.GONE);
            helper.<TextView>getView(R.id.upcominglist_item_cd_txt).setVisibility(View.GONE);
            helper.<TextView>getView(R.id.upcominglist_item_ch_txt).setVisibility(View.GONE);
            switch (item.getStepstatus())
            {
                case 0:
                    helper.<TextView>getView(R.id.upcominglist_item_bj_txt).setVisibility(View.VISIBLE);
                    helper.<TextView>getView(R.id.upcominglist_item_bj_txt).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Intent intent=new Intent(mContext,EditPatrolRecordActivity.class);
                            intent.putExtra(AppConstants.EXTRA_XCJLBID,item.getXcjlbid());
                            mContext.startActivity(intent);
                        }
                    });
                    break;
                case 1:
                    helper.<TextView>getView(R.id.upcominglist_item_ch_txt).setVisibility(View.VISIBLE);
                    helper.<TextView>getView(R.id.upcominglist_item_ch_txt).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            LookPatrolRecordActivity.startLookPatrolRecordActivity(mContext,item.getXcjlbid(),LookPatrolRecordActivity.Type.LOOK,"查看巡查记录表");
                        }
                    });
                    break;
                case 2:
                    helper.<TextView>getView(R.id.upcominglist_item_cd_txt).setVisibility(View.VISIBLE);
                    helper.<TextView>getView(R.id.upcominglist_item_ch_txt).setVisibility(View.VISIBLE);
//                    helper.<TextView>getView(R.id.upcominglist_item_bj_txt).setVisibility(View.VISIBLE);
//                    helper.<TextView>getView(R.id.upcominglist_item_bj_txt).setOnClickListener(new View.OnClickListener() {
//                        @Override
//                        public void onClick(View v) {
//                            Intent intent=new Intent(mContext,EditPatrolRecordActivity.class);
//                            intent.putExtra(AppConstants.EXTRA_XCJLBID,item.getXcjlbid());
//                            mContext.startActivity(intent);
//                        }
//                    });
                    helper.<TextView>getView(R.id.upcominglist_item_ch_txt).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            LookPatrolRecordActivity.startLookPatrolRecordActivity(mContext,item.getXcjlbid(),LookPatrolRecordActivity.Type.EDIT,"查看巡查记录表");
                        }
                    });
                    helper.<TextView>getView(R.id.upcominglist_item_cd_txt).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            LookPatrolRecordActivity.startLookPatrolRecordActivity(mContext,item.getXcjlbid(),LookPatrolRecordActivity.Type.FSHZBCD,"发送给河长办存档");
                        }
                    });
                    break;
                case 3:
                    helper.<TextView>getView(R.id.upcominglist_item_ch_txt).setVisibility(View.VISIBLE);
                    helper.<TextView>getView(R.id.upcominglist_item_ch_txt).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            LookPatrolRecordActivity.startLookPatrolRecordActivity(mContext,item.getXcjlbid(),LookPatrolRecordActivity.Type.LOOK,"查看巡查记录表");
                        }
                    });
                    break;
                    default:
                        //9的情况
                        helper.<TextView>getView(R.id.upcominglist_item_ch_txt).setVisibility(View.VISIBLE);
                        helper.<TextView>getView(R.id.upcominglist_item_ch_txt).setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                LookPatrolRecordActivity.startLookPatrolRecordActivity(mContext,item.getXcjlbid(),LookPatrolRecordActivity.Type.LOOK,"查看巡查记录表");
                            }
                        });
                        break;
            }

        }

    }
}
